package view.game2048;

import java.util.HashMap;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Display;
/**
 * The Game2048ColorFactory class generates the tile color, using the factory design pattern.
 * 
 * @author Peled Eldan
 * @author Daniel Manor
 */
public class Game2048ColorFactory 
{
	// Data Members
	private HashMap<Integer,ColorCreator> slotColorHashCreator;
	private HashMap<Integer,ColorCreator> textColorHashCreator;
	
	// CTOR
	public Game2048ColorFactory()
	{
		slotColorHashCreator = new HashMap<Integer,ColorCreator>()	 	 ;
		slotColorHashCreator.put	(0,		new Color0Creator()			);
		slotColorHashCreator.put	(2,		new Color2Creator()			);
		slotColorHashCreator.put	(4,		new Color4Creator()			);
		slotColorHashCreator.put	(8, 	new Color8Creator()			);
		slotColorHashCreator.put	(16,	new Color16Creator()		);
		slotColorHashCreator.put	(32,	new Color32Creator()		);
		slotColorHashCreator.put	(64,	new Color64Creator()		);
		slotColorHashCreator.put	(128,	new Color128Creator()		);
		slotColorHashCreator.put	(256,	new Color256Creator()		);
		slotColorHashCreator.put	(512,	new Color512Creator()		);
		slotColorHashCreator.put	(1024,	new Color1024Creator()		);
		slotColorHashCreator.put	(2048,	new Color2048Creator()		);
		slotColorHashCreator.put	(4096,	new Color4096Creator()		);
		slotColorHashCreator.put	(8192,	new Color8192Creator()		);
		
		textColorHashCreator = new HashMap<Integer,ColorCreator>()		 ;
		textColorHashCreator.put	(0,		new Color0TextCreator()		);
		textColorHashCreator.put	(2, 	new Color2TextCreator() 	);
		textColorHashCreator.put	(4, 	new Color4TextCreator()		);
		textColorHashCreator.put	(8, 	new Color8TextCreator()		);
		textColorHashCreator.put	(16,	new Color16TextCreator()	);
		textColorHashCreator.put	(32,	new Color32TextCreator()	);
		textColorHashCreator.put	(64,	new Color64TextCreator()	);
		textColorHashCreator.put	(128,	new Color128TextCreator()	);
		textColorHashCreator.put	(256,	new Color256TextCreator()	);
		textColorHashCreator.put	(512,	new Color512TextCreator()	);
		textColorHashCreator.put	(1024,	new Color1024TextCreator()	);
		textColorHashCreator.put	(2048,	new Color2048TextCreator()	);
		textColorHashCreator.put	(4096,	new Color4096TextCreator()	);
		textColorHashCreator.put	(8192,	new Color8192TextCreator()	);
	}
	
	public Color createColor(Integer integer)
	{
		ColorCreator colorCreator = slotColorHashCreator.get(integer);
		if (colorCreator != null)
			return colorCreator.create();
		else
			return null;
	}
	
	public Color createTextColor(Integer integer)
	{
		ColorCreator colorCreator = textColorHashCreator.get(integer);
		if (colorCreator != null)
			return colorCreator.create();
		else
			return null;
	}
	
	private interface ColorCreator
	{
		public Color create();
	}
	
	
	private class Color0Creator implements ColorCreator
	{
		@Override
		public Color create()
		{
			return (new Color(Display.getCurrent(), 203, 191, 178));
		}
	}
	
	private class Color2Creator implements ColorCreator
	{
		@Override
		public Color create()
		{
			return (new Color(Display.getCurrent(), 238, 228, 218));
		}
	}
	
	private class Color4Creator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 175, 144, 112));
		}
	}
	
	private class Color8Creator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 190, 209, 229));
		}
	}
	
	private class Color16Creator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 78, 109, 93));
		}
	}
	
	private class Color32Creator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 66, 70, 255));
		}
	}
	
	private class Color64Creator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 255, 113, 51));
		}
	}
	
	private class Color128Creator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 237, 43, 43));
		}
	}
	
	private class Color256Creator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 62, 12, 100));
		}
	}
	
	private class Color512Creator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 10, 86, 10));
		}
	}
	
	private class Color1024Creator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 154, 252, 0));
		}
	}
	
	private class Color2048Creator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 18, 255, 0));
		}
	}
	
	private class Color4096Creator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 94, 218, 146));
		}
	}
	
	private class Color8192Creator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 62, 57, 51));
		}
	}
	
	private class Color0TextCreator implements ColorCreator
	{
		@Override
		public Color create()
		{
			return (new Color(Display.getCurrent(), 0, 0, 0));
		}
	}
	
	private class Color2TextCreator implements ColorCreator
	{
		@Override
		public Color create()
		{
			return (new Color(Display.getCurrent(), 119, 110, 101));
		}
	}
	
	private class Color4TextCreator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 119, 110, 101));
		}
	}
	
	private class Color8TextCreator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 249, 246, 241));
		}
	}
	
	private class Color16TextCreator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 249, 246, 241));
		}
	}
	
	private class Color32TextCreator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 249, 246, 241));
		}
	}
	
	private class Color64TextCreator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 249, 246, 241));
		}
	}
	
	private class Color128TextCreator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 249, 246, 241));
		}
	}
	
	private class Color256TextCreator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 249, 246, 241));
		}
	}
	
	private class Color512TextCreator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 249, 246, 241));
		}
	}
	
	private class Color1024TextCreator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 255, 247, 218));
		}
	}
	
	private class Color2048TextCreator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 255, 255, 255));
		}
	}
	
	private class Color4096TextCreator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 255, 255, 255));
		}
	}
	
	private class Color8192TextCreator implements ColorCreator
	{
		@Override
		public Color create() 
		{
			return (new Color(Display.getCurrent(), 255, 255, 255));
		}
	}

}